package cn.swjtuhc.ss.hljapi.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.swjtuhc.ss.hljapi.common.Result;
import cn.swjtuhc.ss.hljapi.pojo.Volunteer;
import cn.swjtuhc.ss.hljapi.pojo.VolunteerLoginRequest;
import cn.swjtuhc.ss.hljapi.pojo.response.VolunteerLoginResponse;
import cn.swjtuhc.ss.hljapi.service.VolunteerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 程序狗没有春天
 * @version 1.00
 * @createTime 2024/8/27 19:47
 */
@Slf4j
@RequestMapping("/api/volunteer")
@RestController
public class VolunteerController {
    @Autowired
    private VolunteerService volunteerService;
    @PostMapping("/register")
    public Result<?> register(@RequestBody Volunteer volunteer){
        volunteerService.register(volunteer);
        return Result.success("注册成功");
    }
    @PostMapping("/login")
    public Result<VolunteerLoginResponse> login(@RequestBody VolunteerLoginRequest request){
        VolunteerLoginResponse response = volunteerService.login(request);
        StpUtil.login(response.getId());
        response.setTokenValue(StpUtil.getTokenValue());
        response.setTokenName(StpUtil.getTokenName());
        return Result.success(response);
    }

}
